package cn.taobaoke.restful.controller.admin;

import cn.taobaoke.restful.controller.BaseController;
import cn.taobaoke.restful.interceptor.Auth;
import cn.taobaoke.restful.service.AgentService;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

@RestController
@RequestMapping("/{domain}/{domainId}/api/admins")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class AgentEndpoint extends BaseController {

    @PostMapping("/agents/import")
    @Auth(type = {Auth.AuthType.ADMIN})
    public Result importAgents(@PathVariable Long domainId, @RequestParam("file") MultipartFile file) throws IOException {
        Map<String, String> result = agentService.batchCreateAgents(file.getInputStream(), file.getOriginalFilename(), domainId);
        return wrapObj(result);
    }

    private final @NonNull
    AgentService agentService;
}
